package cn.ciis.basic.model.mongo;

import cn.ciis.basic.model.Equipment;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.cybermkd.mongo.kit.MongoBean;
import org.tio.core.stat.ChannelStat;

/**
 * DeviceConnectInfo
 */
public class DeviceConnectInfo extends MongoBean{

    private String enterprise_code;//企业code
    private String equipment_code;//设备code
    private String ip;//ip地址
    private int port;//连接端口
    private String address;//根据IP地址转换出来的物理地址
    private String name;//设备名字
    private String connectionAt;//连接时间
    private String disconnectionAt;//断开时间
    private Long runningTime;//运行总时间

    /**
     * 本连接服务器发送的字节数
     */
    public Long sentBytes;
    /**
     * 本连接服务器发送的packet数
     */
    public Long	sentPackets;
    /**
     * 本连接已处理的字节数
     */
    public Long	handledBytes;
    /**
     * 本连接已处理的packet数
     */
    public Long	handledPackets;
    /**
     * 处理消息包耗时，单位：毫秒
     * 拿这个值除以handledPackets，就是处理每个消息包的平均耗时
     */
    public Long	handledPacketCosts;
    /**
     * 本连接已接收的字节数
     */
    public Long	receivedBytes;
    /**
     * 本连接已接收了多少次TCP数据包
     */
    public Long	receivedTcps;
    /**
     * 本连接已接收的packet数
     */
    public Long	receivedPackets;

    public String getEnterprise_code() {
        return enterprise_code;
    }

    public void setEnterprise_code(String enterprise_code) {
        this.enterprise_code = enterprise_code;
    }

    public String getEquipment_code() {
        return equipment_code;
    }

    public void setEquipment_code(String equipment_code) {
        this.equipment_code = equipment_code;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getConnectionAt() {
        return connectionAt;
    }

    public void setConnectionAt(String connectionAt) {
        this.connectionAt = connectionAt;
    }

    public String getDisconnectionAt() {
        return disconnectionAt;
    }

    public void setDisconnectionAt(String disconnectionAt) {
        this.disconnectionAt = disconnectionAt;
    }

    public Long getRunningTime() {
        return runningTime;
    }

    public void setRunningTime(Long runningTime) {
        this.runningTime = runningTime;
    }

    public Long getSentBytes() {
        return sentBytes;
    }

    public Long getSentPackets() {
        return sentPackets;
    }

    public Long getHandledBytes() {
        return handledBytes;
    }

    public Long getHandledPackets() {
        return handledPackets;
    }

    public Long getHandledPacketCosts() {
        return handledPacketCosts;
    }

    public Long getReceivedBytes() {
        return receivedBytes;
    }

    public Long getReceivedTcps() {
        return receivedTcps;
    }

    public Long getReceivedPackets() {
        return receivedPackets;
    }

    public void setEquipment(Equipment equipment){
        this.connectionAt = DateUtil.format(equipment.getConnectionAt(), "yyyy-MM-dd HH:mm:ss");
        this.disconnectionAt = DateUtil.format(equipment.getDisconnectionAt(), "yyyy-MM-dd HH:mm:ss");
        this.equipment_code = equipment.getCode();
        this.ip = equipment.getIp();
        this.port = equipment.getPort();
        this.name = equipment.getName();
        this.runningTime = DateUtil.between(equipment.getConnectionAt(), equipment.getDisconnectionAt(), DateUnit.SECOND);
    }

    public void setStat(ChannelStat stat){

        this.sentBytes = stat.getSentBytes().longValue();
        this.sentPackets = stat.getSentPackets().longValue();
        this.handledBytes = stat.getHandledBytes().longValue();
        this.handledPackets = stat.getHandledPackets().longValue();
        this.handledPacketCosts = stat.handledPacketCosts.longValue();
        this.receivedBytes = stat.receivedBytes.longValue();
        this.receivedTcps = stat.receivedTcps.longValue();
        this.receivedPackets = stat.receivedPackets.longValue();
    }

    public DeviceConnectInfo(Equipment equipment, String enterprise_code, ChannelStat stat) {
        this.enterprise_code = enterprise_code;
        this.setEquipment(equipment);
        this.setStat(stat);
    }

    public DeviceConnectInfo() {
    }
    
    
}